import com.okaysoft.ofb.account.UserRole
import com.okaysoft.ofb.account.User
import com.okaysoft.ofb.account.Role
import com.okaysoft.ofb.account.Requestmap
import com.okaysoft.ofb.account.Module
import com.okaysoft.ofb.CompositionDetails

class BootStrap {

    def init = { servletContext ->
        def adminRole = new Role(name:'系统管理员',authority: 'ROLE_ADMIN').save(flush: true)
        def userRole = new Role(name:'设计员',authority: 'ROLE_DESIGNER').save(flush: true)
        def userRole1 = new Role(name:'施工员',authority: 'ROLE_WORKER').save(flush: true)

        def testUser = new User(name: '系统管理员', username: 'admin', enabled: true, password: '1')
        testUser.save(flush: true)
        UserRole.create testUser, adminRole, true
        UserRole.create testUser, userRole, true

        def testUser1 = new User(name: '刘设计', username: 'des', enabled: true, password: '1')
        testUser1.save(flush: true)
        UserRole.create testUser1, userRole, true

        def testUser2 = new User(name: '张施工', username: 'work', enabled: true, password: '1')
        testUser2.save(flush: true)
        UserRole.create testUser2, userRole1, true

        /*def m = new Module(name: '用户管理')
        def m1 = new Module(name: '角色管理')
        m.save(flush: true)
        m1.save(flush: true)*/
       new Requestmap(name: '首页', url: '/*', configAttribute: 'IS_AUTHENTICATED_FULLY',link: '/').save(flush: true)
        new Requestmap(name: '光交设备管理', url: '/device/**', configAttribute: 'ROLE_ADMIN,ROLE_DESIGNER',link: '/device',menuEnabled: true,orderNumber: 1).save(flush: true)
       new Requestmap(name: '任务管理', url: '/task/**', configAttribute: 'ROLE_ADMIN,ROLE_DESIGNER',link: '/task',menuEnabled: true,orderNumber: 10).save(flush: true)
       //new Requestmap(name: '地理信息', url: '/location/**', configAttribute: 'ROLE_ADMIN',link: '/location',menuEnabled: true).save(flush: true)
        new Requestmap(name: '模板管理', url: '/formwork/**', configAttribute: 'ROLE_ADMIN',link: '/formwork',menuEnabled: true,orderNumber: 20).save(flush: true)
       new Requestmap(name: '通信用户', url: '/client/**', configAttribute: 'ROLE_ADMIN,ROLE_DESIGNER',link: '/client',menuEnabled: true,orderNumber: 30).save(flush: true)
        new Requestmap(name: '系统管理', url: '/system/**', configAttribute: 'ROLE_ADMIN',link: '/system',menuEnabled: true,orderNumber: 40).save(flush: true)
        new Requestmap(name: '部门管理', url: '/department/**', configAttribute: 'ROLE_ADMIN',link: '/department').save(flush: true)
        new Requestmap(name: '修改密码', url: '/user/changePassword/**', configAttribute: 'IS_AUTHENTICATED_FULLY',link: '/user/changePassword').save(flush: true)
        new Requestmap(name: '修改密码保存', url: '/user/updatePassword/**', configAttribute: 'IS_AUTHENTICATED_FULLY',link: '/user/updatePassword').save(flush: true)
        new Requestmap(name: '用户管理', url: '/user/**', configAttribute: 'ROLE_ADMIN',link: '/user').save(flush: true)
        new Requestmap(name: '角色管理', url: '/role/**', configAttribute: 'ROLE_ADMIN',link: '/role').save(flush: true)
        new Requestmap(name: '权限管理', url: '/requestMap/**', configAttribute: 'ROLE_ADMIN',link: '/requestMap').save(flush: true)
//       /// def r4 = new Requestmap(name: '模块管理', url: '/module*//**', configAttribute: 'ROLE_ADMIN',link: '/module').save(flush: true)

        new CompositionDetails(name: 'c_1_1',area: '1', x: '40',y:'18',width: '625',height:'303').save(flush: true)

        new CompositionDetails(name: 'c_2_1',area: '1', x: '40',y:'18',width: '280',height:'300').save(flush: true)
        new CompositionDetails(name: 'c_2_1',area: '2', x: '360',y:'18',width: '280',height:'300').save(flush: true)

        new CompositionDetails(name: 'c_2_2',area: '1', x: '40',y:'10',width: '600',height:'290').save(flush: true)
        new CompositionDetails(name: 'c_2_2',area: '2', x: '40',y:'315',width: '600',height:'290').save(flush: true)

        new CompositionDetails(name: 'c_3_1',area: '1', x: '40',y:'10',width: '600',height:'290').save(flush: true)
        new CompositionDetails(name: 'c_3_1',area: '2', x: '40',y:'315',width: '600',height:'290').save(flush: true)
        new CompositionDetails(name: 'c_3_1',area: '3', x: '40',y:'620',width: '600',height:'290').save(flush: true)

        new CompositionDetails(name: 'c_3_2',area: '1', x: '15',y:'20',width: '210',height:'300').save(flush: true)
        new CompositionDetails(name: 'c_3_2',area: '2', x: '240',y:'20',width: '210',height:'300').save(flush: true)
        new CompositionDetails(name: 'c_3_2',area: '3', x: '465',y:'20',width: '210',height:'300').save(flush: true)

        new CompositionDetails(name: 'c_3_3',area: '1', x: '40',y:'10',width: '280',height:'590').save(flush: true)
        new CompositionDetails(name: 'c_3_3',area: '2', x: '360',y:'10',width: '280',height:'290').save(flush: true)
        new CompositionDetails(name: 'c_3_3',area: '3', x: '360',y:'310',width: '280',height:'290').save(flush: true)

        new CompositionDetails(name: 'c_3_4',area: '1', x: '40',y:'10',width: '280',height:'290').save(flush: true)
        new CompositionDetails(name: 'c_3_4',area: '2', x: '360',y:'10',width: '280',height:'590').save(flush: true)
        new CompositionDetails(name: 'c_3_4',area: '3', x: '40',y:'310',width: '280',height:'290').save(flush: true)

        new CompositionDetails(name: 'c_3_5',area: '1', x: '40',y:'10',width: '600',height:'290').save(flush: true)
        new CompositionDetails(name: 'c_3_5',area: '2', x: '40',y:'310',width: '280',height:'290').save(flush: true)
        new CompositionDetails(name: 'c_3_5',area: '3', x: '360',y:'310',width: '280',height:'290').save(flush: true)

        new CompositionDetails(name: 'c_3_6',area: '1', x: '40',y:'10',width: '280',height:'290').save(flush: true)
        new CompositionDetails(name: 'c_3_6',area: '2', x: '360',y:'10',width: '280',height:'290').save(flush: true)
        new CompositionDetails(name: 'c_3_6',area: '3', x: '40',y:'310',width: '600',height:'290').save(flush: true)
    }
    def destroy = {
    }
}
